package presentacion;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JButton;

import negocio.TransferAdministrativo;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class GUIAdministradorNuevoPago extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;
	private JFrame esta;
	private TransferAdministrativo 	_datos;
	public GUIAdministrativo ventanaPadre;
	private JTextArea textArea;
	

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					GUIAdministradorNuevoPago frame = new GUIAdministradorNuevoPago(null);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public GUIAdministradorNuevoPago(GUIAdministrativo ventana) {
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		this.ventanaPadre=ventana;
		_datos = new TransferAdministrativo();
		this.setVisible(true);
		esta=this;
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("Motivo :");
		lblNewLabel.setBounds(60, 66, 46, 14);
		contentPane.add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("Cantidad :");
		lblNewLabel_1.setBounds(60, 41, 66, 14);
		contentPane.add(lblNewLabel_1);
		
		JLabel lblNewLabel_2 = new JLabel("Descripcion :");
		lblNewLabel_2.setBounds(60, 91, 66, 14);
		contentPane.add(lblNewLabel_2);
		
		textField = new JTextField();
		textField.setBounds(189, 38, 86, 20);
		contentPane.add(textField);
		textField.setColumns(10);
		
		textField_1 = new JTextField();
		textField_1.setBounds(189, 63, 86, 20);
		contentPane.add(textField_1);
		textField_1.setColumns(10);
		
		textArea = new JTextArea();
		textArea.setBounds(60, 116, 302, 89);
		contentPane.add(textArea);
		
		JButton btnNewButton = new JButton("ACEPTAR");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				try{
				String motivo=textField_1.getText();
				String importes=textField.getText();
				int importe=Integer.parseInt(importes);
				String descripcion= textArea.getText();
				if(motivo=="" ||importes==""){
					throw new Exception("incompletos");
				}else{
					_datos.setDescripcion(descripcion);
					_datos.setMotivo(motivo);
					_datos.setImporte(importe);
					SingletonControlador.getInstancia().evento(Evento.A_NUEVA_CUENTA, _datos);
					ventanaPadre.actualizar();
					esta.dispose();
				}
				}catch(Exception e1){
				JOptionPane.showMessageDialog(esta, "Datos incompletos o incorrectos.");
				}
			}
		});
		btnNewButton.setBounds(168, 216, 89, 23);
		contentPane.add(btnNewButton);
		
		JLabel lblNewLabel_3 = new JLabel("NUEVO PAGO");
		lblNewLabel_3.setBounds(168, 11, 73, 14);
		contentPane.add(lblNewLabel_3);
	}
}
